<template>
	<view>
		<form @submit="formSubmit" report-submit="true">
			<view class="personal-data">
				<view class="tips">您的资料未完善，请补充完整。</view>
				<view class="list">
					<!-- <view class="item acea-row row-between-wrapper">
						<view>头像</view>
						<view class="pictrue" @click.stop="uploadpic">
							<image :src="userInfo.localPath"></image>
							<image src="../../../static/images/alter.png" class="alter"></image>
						</view>
					</view>
					<view class="item acea-row row-between-wrapper">
						<view>昵称</view>
						<view class="input"><input type="text" name="nickname" :value="userInfo.nickname" /></view>
					</view> -->
					<view class="item acea-row row-between-wrapper">
						<view>身份</view>
						<view class="input"><input type="text" name="phone" :value="userInfo.markName" class="id" />
						</view>
					</view>
					<view class="item acea-row row-between-wrapper">
						<view>姓名<text style="color: red;">*</text></view>
						<view class="input"><input type="text" name="realName" :value="userInfo.realName" class="id" />
						</view>
					</view>
					<view class="item acea-row row-between-wrapper">
						<view>身份证<text style="color: red;">*</text></view>
						<view class="input"><input type="text" name="cardId" :value="userInfo.cardId" class="id" />
						</view>
					</view>
					<view class="item acea-row row-between-wrapper">
						<view>手机号码<text style="color: red;">*</text></view>
						<view class="input"><input type="text" name="phone" :value="userInfo.phone" class="id" /></view>
					</view>
					<view class="item acea-row row-between-wrapper">
						<view>会员卡号</view>
						<view class="input acea-row row-between-wrapper">
							<input type="text" :value="userInfo.userNo" v-if="userInfo.userNo" disabled="true"
								class="id" />
							<text v-else class="userNo">请联系店铺,由店员补充您的实体会员卡号</text>
							<text class="iconfont icon-suozi"></text>
						</view>
					</view>
					<view class="item acea-row row-between-wrapper">
						<view>权限设置</view>
						<view class="input" @click="Setting">
							点击管理
							<text class="iconfont icon-xiangyou"></text>
						</view>
					</view>
				</view>
				<button class="modifyBnt bg-color" formType="submit">保存修改</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		getUserInfo,
		userEdit,
		getLogout
	} from '@/api/user.js';
	import {
		switchH5Login
	} from '@/api/api.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from 'vuex';
	import dayjs from '@/plugin/dayjs/dayjs.min.js';
	import authorize from '@/components/Authorize';

	export default {
		components: {
			authorize
		},
		data() {
			return {
				userInfo: {},
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false //是否隐藏授权
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getUserInfo();
					}
				},
				deep: true
			}
		},
		onLoad() {
			if (this.isLogin) {
				this.getUserInfo();
			} else {
				this.isAuto = true;
				this.$set(this, 'isShowAuth', true);
			}
		},
		methods: {
			/**
			 * 授权回调
			 */
			onLoadFun: function() {
				this.getUserInfo();
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e;
			},
			/**
			 * 小程序设置
			 */
			Setting: function() {
				uni.openSetting({
					success: function(res) {
						console.log(res.authSetting);
					}
				});
			},
			/**
			 * 获取用户详情
			 */
			getUserInfo: function() {
				let that = this;
				getUserInfo().then(res => {
					res.data.localPath = res.data.avatar;
					that.$set(that, 'userInfo', res.data);
					that.$store.commit('UPDATE_USERINFO', res.data);
					that.$store.commit('SETUID', res.data.uid);
				});
			},
			/**
			 * 上传文件
			 *
			 */
			uploadpic: function() {
				let that = this;
				that.$util.uploadImageOne({
					url: 'user/upload/image',
					name: 'multipart',
					model: 'user',
					pid: 7
				}, function(res) {
					that.userInfo.avatar = res.data.url;
					that.$set(that.userInfo, 'localPath', res.data.localPath);
				});
			},

			/**
			 * 提交修改
			 */
			formSubmit: function(e) {
				let that = this,
					value = e.detail.value;
				// if (!value.nickname)
				// 	return that.$util.Tips({
				// 		title: '昵称不能为空'
				// 	});
				value.avatar = that.userInfo.avatar;
				value.nickname = that.userInfo.nickname;
				if (!value.realName)
					return that.$util.Tips({
						title: '请填写姓名'
					});
				if (!value.cardId)
					return that.$util.Tips({
						title: '请填写身份证号'
					});
				if (!value.phone)
					return that.$util.Tips({
						title: '请填写手机号码'
					});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(value.phone))
					return that.$util.Tips({
						title: '请填写正确的手机号码'
					});
				userEdit(value)
					.then(res => {
						return that.$util.Tips({
							title: '更新成功',
							icon: 'success'
						}, {
							tab: 3,
							url: 1
						});
					})
					.catch(msg => {
						return that.$util.Tips({
							title: msg || '保存失败，您并没有修改'
						}, {
							tab: 3,
							url: 1
						});
					});
			}
		}
	};
</script>

<style scoped lang="scss">
	.tips {
		padding: 30rpx 30rpx 0;
		color: #E93323;
	}

	.personal-data .wrapper {
		margin: 10rpx 0;
		background-color: #fff;
		padding: 36rpx 30rpx 13rpx 30rpx;
	}

	.personal-data .wrapper .title {
		margin-bottom: 30rpx;
		font-size: 32rpx;
		color: #282828;
	}

	.personal-data .wrapper .wrapList .item {
		width: 690rpx;
		height: 160rpx;
		background-color: #f8f8f8;
		border-radius: 20rpx;
		margin-bottom: 22rpx;
		padding: 0 30rpx;
		position: relative;
		border: 2rpx solid #f8f8f8;
		box-sizing: border-box;
	}

	.personal-data .wrapper .wrapList .item.on {
		border-color: #e93323;
		border-radius: 20rpx;
		background-image: url('');
		background-size: 100% 100%;
		background-color: #fff9f9;
		background-repeat: no-repeat;
	}

	.personal-data .wrapper .wrapList .item .picTxt {
		width: 445rpx;
	}

	.personal-data .wrapper .wrapList .item .picTxt .pictrue {
		width: 96rpx;
		height: 96rpx;
		position: relative;
	}

	.personal-data .wrapper .wrapList .item .picTxt .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	.personal-data .wrapper .wrapList .item .picTxt .pictrue .alter {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		position: absolute;
		bottom: 0;
		right: 0;
	}

	.personal-data .wrapper .wrapList .item .picTxt .text {
		width: 325rpx;
	}

	.personal-data .wrapper .wrapList .item .picTxt .text .name {
		width: 100%;
		font-size: 30rpx;
		color: #282828;
	}

	.personal-data .wrapper .wrapList .item .picTxt .text .phone {
		font-size: 24rpx;
		color: #999;
		margin-top: 10rpx;
	}

	.personal-data .wrapper .wrapList .item .bnt {
		font-size: 24rpx;
		background-color: #fff;
		border-radius: 27rpx;
		width: 140rpx;
		height: 54rpx;
		border: 2rpx solid #e93323;
	}

	.personal-data .wrapper .wrapList .item .currentBnt {
		position: absolute;
		right: 0;
		top: 0;
		font-size: 26rpx;
		background-color: rgba(233, 51, 35, 0.1);
		width: 140rpx;
		height: 48rpx;
		border-radius: 0 20rpx 0 20rpx;
	}

	.personal-data .list {
		margin-top: 15rpx;
		background-color: #fff;
	}

	.personal-data .list .item {
		padding: 30rpx 30rpx 30rpx 0;
		border-bottom: 1rpx solid #f2f2f2;
		margin-left: 30rpx;
		font-size: 32rpx;
		color: #282828;
	}

	.personal-data .list .item .phone {
		width: 160rpx;
		height: 56rpx;
		font-size: 24rpx;
		color: #fff;
		line-height: 56rpx;
		border-radius: 32rpx;
	}

	.personal-data .list .item .pictrue {
		width: 88rpx;
		height: 88rpx;
		position: relative;
	}

	.personal-data .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	.personal-data .list .item .pictrue .alter {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		position: absolute;
		bottom: 0;
		right: 0;
	}

	.personal-data .list .item .input {
		flex-wrap: nowrap;
		width: 415rpx;
		text-align: right;
		color: #868686;
	}

	.personal-data .list .item .input .id {
		width: 365rpx;
	}

	.personal-data .list .item .input .userNo {
		font-size: 14px;
		color: red;
	}

	.personal-data .list .item .input .iconfont {
		font-size: 35rpx;
	}

	.personal-data .modifyBnt {
		font-size: 32rpx;
		color: #fff;
		width: 690rpx;
		height: 90rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 90rpx;
		margin: 76rpx auto 0 auto;
	}

	.personal-data .logOut {
		font-size: 32rpx;
		text-align: center;
		width: 690rpx;
		height: 90rpx;
		border-radius: 45rpx;
		margin: 30rpx auto 0 auto;
	}
</style>
